/**
 * @description shop router
 * @author liyunfu
 */

const router = require("koa-router")();
const { SuccessModel, ErrorModel } = require("../res-model/index");
const {
  getHotList,
  getShopInfo,
  getProductsByShopId,
} = require("../controller/shop");
router.prefix("/api/shop");

//商店列表
router.get("/hot-list", async (ctx, next) => {
  //获取列表
  const list = await getHotList();
  ctx.body = new SuccessModel(list);
});
//单个商店信息
router.get("/:id", async (ctx, next) => {
  const id = ctx.params.id;
  const shop = await getShopInfo(id);
  ctx.body = new SuccessModel(shop);
});
//获取商店的商品
router.get("/:id/products", async (ctx, next) => {
  const shopId = ctx.params.id;
  const tab = ctx.query.tab || "all"; //query里的tab参数默认为all
  //获取商品
  const products = await getProductsByShopId(shopId, tab);
  ctx.body = new SuccessModel(products);
});
module.exports = router;
